@ampless/admin 0.2.0-alpha.1 → 0.2.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/api/index.d.ts +1 -1
  2. package/dist/chunk-2ITWLRYF.js +38 -0
  3. package/dist/chunk-4YEBIBFG.js +48 -0
  4. package/dist/chunk-5OIPGVGG.js +198 -0
  5. package/dist/chunk-7IJDOT2K.js +1197 -0
  6. package/dist/chunk-7IR4F7GA.js +6 -0
  7. package/dist/chunk-BFZODSUT.js +71 -0
  8. package/dist/chunk-BYLCQYEQ.js +21 -0
  9. package/dist/chunk-GDQC5X46.js +250 -0
  10. package/dist/chunk-OFHKZNZS.js +33 -0
  11. package/dist/{chunk-TJR3ALRJ.js → chunk-OPQ3SAZJ.js} +75 -66
  12. package/dist/chunk-QVUTNQZH.js +21 -0
  13. package/dist/chunk-TZWSXAHD.js +32 -0
  14. package/dist/chunk-UOU7KQLR.js +149 -0
  15. package/dist/chunk-VXEVLHGL.js +10 -0
  16. package/dist/chunk-XHWECTED.js +1125 -0
  17. package/dist/chunk-XXJDT6FF.js +335 -0
  18. package/dist/chunk-XZQRPXKN.js +41 -0
  19. package/dist/components/admin-dashboard.d.ts +10 -0
  20. package/dist/components/admin-dashboard.js +9 -0
  21. package/dist/components/edit-post-view.d.ts +9 -0
  22. package/dist/components/edit-post-view.js +14 -0
  23. package/dist/components/index.d.ts +32 -19
  24. package/dist/components/index.js +33 -15
  25. package/dist/components/login-view.d.ts +5 -0
  26. package/dist/components/login-view.js +9 -0
  27. package/dist/components/media-view.d.ts +5 -0
  28. package/dist/components/media-view.js +12 -0
  29. package/dist/components/new-post-view.d.ts +5 -0
  30. package/dist/components/new-post-view.js +14 -0
  31. package/dist/components/posts-list-view.d.ts +5 -0
  32. package/dist/components/posts-list-view.js +11 -0
  33. package/dist/components/users-list-view.d.ts +7 -0
  34. package/dist/components/users-list-view.js +9 -0
  35. package/dist/{i18n-ByHM_Bho.d.ts → i18n-DzXXcIQQ.d.ts} +110 -1
  36. package/dist/index.d.ts +2 -2
  37. package/dist/index.js +7 -3
  38. package/dist/lib/theme-actions.d.ts +17 -0
  39. package/dist/lib/theme-actions.js +7 -0
  40. package/dist/metafile-esm.json +1 -0
  41. package/dist/pages/index.d.ts +49 -15
  42. package/dist/pages/index.js +114 -658
  43. package/package.json +10 -9
  44. package/dist/chunk-T2RSMFOI.js +0 -2074
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from 'next/server';
2
2
  import { Admin } from '../index.js';
3
3
  import 'ampless';
4
4
  import '@ampless/runtime';
5
- import '../i18n-ByHM_Bho.js';
5
+ import '../i18n-DzXXcIQQ.js';
6
6
  import '@aws-amplify/adapter-nextjs';
7
7
 
8
8
  /**
@@ -0,0 +1,38 @@
1
+ // src/lib/media.ts
2
+ var state = { outputs: null, cmsConfig: null };
3
+ function setAdminMediaContext(outputs, cmsConfig) {
4
+ state.outputs = outputs;
5
+ state.cmsConfig = cmsConfig;
6
+ }
7
+ function publicMediaUrl(input) {
8
+ if (/^https?:\/\//.test(input)) return input;
9
+ let path = input.replace(/^\/+/, "");
10
+ if (path.startsWith("public/")) path = path.slice("public/".length);
11
+ const { outputs, cmsConfig } = state;
12
+ const delivery = cmsConfig?.media?.delivery ?? "nextjs";
13
+ if (delivery !== "s3-direct") return `/api/media/${path}`;
14
+ const storage = outputs?.storage;
15
+ if (!storage) return `/api/media/${path}`;
16
+ return `https://${storage.bucket_name}.s3.${storage.aws_region}.amazonaws.com/public/${path}`;
17
+ }
18
+ function createMedia(outputs, cmsConfig) {
19
+ const storage = outputs.storage;
20
+ function s3DirectUrl(path) {
21
+ if (!storage) return `/api/media/${path}`;
22
+ return `https://${storage.bucket_name}.s3.${storage.aws_region}.amazonaws.com/public/${path}`;
23
+ }
24
+ function urlFor(input) {
25
+ if (/^https?:\/\//.test(input)) return input;
26
+ let path = input.replace(/^\/+/, "");
27
+ if (path.startsWith("public/")) path = path.slice("public/".length);
28
+ const delivery = cmsConfig.media?.delivery ?? "nextjs";
29
+ return delivery === "s3-direct" ? s3DirectUrl(path) : `/api/media/${path}`;
30
+ }
31
+ return { publicMediaUrl: urlFor };
32
+ }
33
+
34
+ export {
35
+ setAdminMediaContext,
36
+ publicMediaUrl,
37
+ createMedia
38
+ };
@@ -0,0 +1,48 @@
1
+ 'use client';
2
+ import {
3
+ useT
4
+ } from "./chunk-OFHKZNZS.js";
5
+
6
+ // src/components/admin-dashboard.tsx
7
+ import { useEffect, useState } from "react";
8
+ import Link from "next/link";
9
+ import { listPosts } from "ampless";
10
+ import { Button, Card, CardContent, CardHeader, CardTitle } from "@ampless/runtime/ui";
11
+ import { jsx, jsxs } from "react/jsx-runtime";
12
+ function AdminDashboard() {
13
+ const t = useT();
14
+ const [posts, setPosts] = useState([]);
15
+ const [loading, setLoading] = useState(true);
16
+ useEffect(() => {
17
+ listPosts({ status: "all" }).then(setPosts).finally(() => setLoading(false));
18
+ }, []);
19
+ const published = posts.filter((p) => p.status === "published").length;
20
+ const drafts = posts.filter((p) => p.status === "draft").length;
21
+ return /* @__PURE__ */ jsxs("div", { className: "mx-auto max-w-7xl p-4 md:p-8", children: [
22
+ /* @__PURE__ */ jsxs("div", { className: "mb-6 flex flex-wrap items-center justify-between gap-3 md:mb-8", children: [
23
+ /* @__PURE__ */ jsx("h1", { className: "text-2xl font-bold md:text-3xl", children: t("dashboard.title") }),
24
+ /* @__PURE__ */ jsx(Button, { asChild: true, children: /* @__PURE__ */ jsx(Link, { href: "/admin/posts/new", children: t("dashboard.newPost") }) })
25
+ ] }),
26
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3", children: [
27
+ /* @__PURE__ */ jsxs(Card, { children: [
28
+ /* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsx(CardTitle, { children: t("dashboard.totalPosts") }) }),
29
+ /* @__PURE__ */ jsxs(CardContent, { children: [
30
+ /* @__PURE__ */ jsx("p", { className: "text-3xl font-bold", children: loading ? "\u2014" : posts.length }),
31
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("dashboard.totalLabel") })
32
+ ] })
33
+ ] }),
34
+ /* @__PURE__ */ jsxs(Card, { children: [
35
+ /* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsx(CardTitle, { children: t("dashboard.published") }) }),
36
+ /* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsx("p", { className: "text-3xl font-bold", children: loading ? "\u2014" : published }) })
37
+ ] }),
38
+ /* @__PURE__ */ jsxs(Card, { children: [
39
+ /* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsx(CardTitle, { children: t("dashboard.drafts") }) }),
40
+ /* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsx("p", { className: "text-3xl font-bold", children: loading ? "\u2014" : drafts }) })
41
+ ] })
42
+ ] })
43
+ ] });
44
+ }
45
+
46
+ export {
47
+ AdminDashboard
48
+ };
@@ -0,0 +1,198 @@
1
+ 'use client';
2
+ import {
3
+ useT
4
+ } from "./chunk-OFHKZNZS.js";
5
+
6
+ // src/components/login-view.tsx
7
+ import { useState } from "react";
8
+ import { useRouter } from "next/navigation";
9
+ import {
10
+ signIn,
11
+ signUp,
12
+ confirmSignUp,
13
+ resetPassword,
14
+ confirmResetPassword
15
+ } from "aws-amplify/auth";
16
+ import {
17
+ Button,
18
+ Input,
19
+ Label,
20
+ Card,
21
+ CardContent,
22
+ CardHeader,
23
+ CardTitle,
24
+ CardDescription
25
+ } from "@ampless/runtime/ui";
26
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
27
+ function LoginPage() {
28
+ const router = useRouter();
29
+ const t = useT();
30
+ const [mode, setMode] = useState("signIn");
31
+ const [email, setEmail] = useState("");
32
+ const [password, setPassword] = useState("");
33
+ const [code, setCode] = useState("");
34
+ const [error, setError] = useState(null);
35
+ const [info, setInfo] = useState(null);
36
+ const [loading, setLoading] = useState(false);
37
+ function go(next) {
38
+ setMode(next);
39
+ setError(null);
40
+ setInfo(null);
41
+ setCode("");
42
+ if (next === "signIn" || next === "signUp" || next === "forgot") setPassword("");
43
+ }
44
+ async function handleSubmit(e) {
45
+ e.preventDefault();
46
+ setError(null);
47
+ setInfo(null);
48
+ setLoading(true);
49
+ try {
50
+ if (mode === "signIn") {
51
+ const result = await signIn({ username: email, password });
52
+ if (result.isSignedIn) {
53
+ router.push("/admin");
54
+ router.refresh();
55
+ } else {
56
+ setError(t("auth.additionalStep", { step: result.nextStep.signInStep }));
57
+ }
58
+ } else if (mode === "signUp") {
59
+ await signUp({
60
+ username: email,
61
+ password,
62
+ options: { userAttributes: { email } }
63
+ });
64
+ go("confirm");
65
+ } else if (mode === "confirm") {
66
+ await confirmSignUp({ username: email, confirmationCode: code });
67
+ const result = await signIn({ username: email, password });
68
+ if (result.isSignedIn) {
69
+ router.push("/admin");
70
+ router.refresh();
71
+ }
72
+ } else if (mode === "forgot") {
73
+ await resetPassword({ username: email });
74
+ setMode("reset");
75
+ setInfo(t("auth.forgot.codeSent"));
76
+ } else if (mode === "reset") {
77
+ await confirmResetPassword({
78
+ username: email,
79
+ confirmationCode: code,
80
+ newPassword: password
81
+ });
82
+ const result = await signIn({ username: email, password });
83
+ if (result.isSignedIn) {
84
+ router.push("/admin");
85
+ router.refresh();
86
+ } else {
87
+ setMode("signIn");
88
+ setInfo(t("auth.reset.passwordUpdated"));
89
+ }
90
+ }
91
+ } catch (err) {
92
+ setError(err instanceof Error ? err.message : String(err));
93
+ } finally {
94
+ setLoading(false);
95
+ }
96
+ }
97
+ const showEmail = mode !== "confirm" && mode !== "reset";
98
+ const showPassword = mode === "signIn" || mode === "signUp" || mode === "reset";
99
+ const showCode = mode === "confirm" || mode === "reset";
100
+ return /* @__PURE__ */ jsx("main", { className: "flex min-h-screen items-center justify-center bg-muted/30 p-4", children: /* @__PURE__ */ jsxs(Card, { className: "w-full max-w-md", children: [
101
+ /* @__PURE__ */ jsxs(CardHeader, { children: [
102
+ /* @__PURE__ */ jsx(CardTitle, { children: t(`auth.${mode}.title`) }),
103
+ /* @__PURE__ */ jsx(CardDescription, { children: t(`auth.${mode}.description`) })
104
+ ] }),
105
+ /* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "space-y-4", children: [
106
+ showEmail && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
107
+ /* @__PURE__ */ jsx(Label, { htmlFor: "email", children: t("auth.common.email") }),
108
+ /* @__PURE__ */ jsx(
109
+ Input,
110
+ {
111
+ id: "email",
112
+ type: "email",
113
+ required: true,
114
+ value: email,
115
+ onChange: (e) => setEmail(e.target.value),
116
+ autoComplete: "email"
117
+ }
118
+ )
119
+ ] }),
120
+ showCode && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
121
+ /* @__PURE__ */ jsx(Label, { htmlFor: "code", children: t("auth.common.code") }),
122
+ /* @__PURE__ */ jsx(
123
+ Input,
124
+ {
125
+ id: "code",
126
+ required: true,
127
+ value: code,
128
+ onChange: (e) => setCode(e.target.value),
129
+ autoComplete: "one-time-code"
130
+ }
131
+ )
132
+ ] }),
133
+ showPassword && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
134
+ /* @__PURE__ */ jsx(Label, { htmlFor: "password", children: mode === "reset" ? t("auth.common.newPassword") : t("auth.common.password") }),
135
+ /* @__PURE__ */ jsx(
136
+ Input,
137
+ {
138
+ id: "password",
139
+ type: "password",
140
+ required: true,
141
+ minLength: 8,
142
+ value: password,
143
+ onChange: (e) => setPassword(e.target.value),
144
+ autoComplete: mode === "signIn" ? "current-password" : "new-password"
145
+ }
146
+ ),
147
+ (mode === "signUp" || mode === "reset") && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("auth.common.passwordHint") })
148
+ ] }),
149
+ info && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: info }),
150
+ error && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: error }),
151
+ /* @__PURE__ */ jsx(Button, { type: "submit", className: "w-full", disabled: loading, children: loading ? t("auth.common.working") : t(`auth.${mode}.submit`) }),
152
+ /* @__PURE__ */ jsxs("div", { className: "space-y-1 text-center text-sm", children: [
153
+ mode === "signIn" && /* @__PURE__ */ jsxs(Fragment, { children: [
154
+ /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(
155
+ "button",
156
+ {
157
+ type: "button",
158
+ className: "text-primary hover:underline",
159
+ onClick: () => go("forgot"),
160
+ children: t("auth.signIn.forgotPassword")
161
+ }
162
+ ) }),
163
+ /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(
164
+ "button",
165
+ {
166
+ type: "button",
167
+ className: "text-primary hover:underline",
168
+ onClick: () => go("signUp"),
169
+ children: t("auth.signIn.createAccount")
170
+ }
171
+ ) })
172
+ ] }),
173
+ (mode === "signUp" || mode === "forgot" || mode === "reset") && /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(
174
+ "button",
175
+ {
176
+ type: "button",
177
+ className: "text-primary hover:underline",
178
+ onClick: () => go("signIn"),
179
+ children: t("auth.signUp.backToSignIn")
180
+ }
181
+ ) }),
182
+ mode === "reset" && /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(
183
+ "button",
184
+ {
185
+ type: "button",
186
+ className: "text-primary hover:underline",
187
+ onClick: () => go("forgot"),
188
+ children: t("auth.reset.resendCode")
189
+ }
190
+ ) })
191
+ ] })
192
+ ] }) })
193
+ ] }) });
194
+ }
195
+
196
+ export {
197
+ LoginPage
198
+ };